﻿#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    // 35. 搜索插入位置
    int searchInsert(vector<int>& nums, int target)
    {
        int left = 0, right = nums.size() - 1;
        while (left <= right)
        {
            int mid = (left + right) / 2;
            if (nums[mid] < target)
                left = mid + 1;
            else if (nums[mid] > target)
                right = mid - 1;
            else
                return mid;

        }
        return left;
    }

    // 367. 有效的完全平方数
    bool isPerfectSquare(int num)
    {
        int left = 0, right = num;
        while (left <= right)
        {
            int mid = left + (right - left) / 2;
            long long square = (long long)mid * mid;
            if (square < num)
                left = mid + 1;
            else if (square > num)
                right = mid - 1;
            else
                return true;
        }
        return false;
    }
};

int main()
{
    /*vector<int> v{ 1,3 };
    cout << Solution().searchInsert(v, 2) << endl;*/

    cout << Solution().isPerfectSquare(81) << endl;

    return 0;
}